/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package shaman.storage.impl.filter.crypto;

/**
 *
 * @author dmitriy
 */
public class NumberUtil {

    /**
     * Converts an integer into its big-endian 4-byte representation
     * @param number
     * The number to convert
     * @return
     * The byte representation
     */
    public static byte[] intBytesBe(int number)
    {
        byte[] bytes=new byte[4];
        int i;
        for (i=0; i<4; i++)
        {
            bytes[i]=(byte) (number>>(3-i)*8);
        }
        return bytes;
    }

    /**
     * Converts a short integer into its big-endian 2-byte representation
     * @param number
     * The number to convert
     * @return
     * The byte representation
     */
    public static byte[] shortBytesBe(short number)
    {
        byte[] bytes=new byte[2];
        bytes[0]=(byte) (number>>16);
        bytes[1]=(byte) (number&0xFF);
        return bytes;
    }
    /**
     * Calculates bitwise-XOR of the byte sequences given. The byte sequences
     * must be of equal length
     * @param dst
     * The source byte sequence that will be overwritten with the result
     * @param src
     * The source byte sequence that will not be modified
     * @return
     * dst argument
     */
    public static byte[] bitwiseXor(byte[] dst, byte[] src)
    {
        int i;
        for (i=0; i<dst.length; i++)
            dst[i]^=src[i];
        return dst;
    }


}
